#include "queue.h"


//创建一个队列
struct queue *create_queue(){
    struct queue *head = NULL;
    head = malloc(sizeof(struct queue));
    memset(head,0,sizeof(struct queue));

    return head;
}

//入队
void push(struct queue *que,struct msg data){
    struct queue *node = NULL;
    struct queue *temp = que;

    node = malloc(sizeof(struct queue));
    memset(node,0,sizeof(struct queue));
    while(temp->next != NULL){
        temp = temp->next;
    }
    node->data = data;
    temp->next = node;
    node->next = NULL;
    temp = temp->next;
}

//找到队首元素
struct msg front(struct queue *que){
    struct queue *temp = que->next;
    return temp->data;
}

//删除队首元素
void pop(struct queue *que){
    struct queue *temp = que->next;
    que->next = temp->next;
    free(temp);
    temp = NULL;
}

//判断队列是否为空
int isemptyque(struct queue *que){
    if(que->next == NULL){
        return 0;
    }
    return 1;
}

//求队列的大小
int sizeofque(struct queue *que){
    struct queue *temp = que->next;
    int count = 0;
    while(temp != NULL){
        count++;
        temp = temp->next;
    }
    return count;
}

// //清空队列
// void freeque(struct queue *que){
//     struct queue *temp = que->next;
//     while(que != NULL){
//         free(que);
//         que = NULL;
//         que = temp;
//     }
//     temp = NULL;
// }